import 'dart:async';
import 'dart:io';

import 'package:flutter/services.dart';

class FlutterDeviceInfo {
  static const MethodChannel _channel =
      const MethodChannel('plugins/dk_flutter_device_info');

  /// This information does not change from call to call. Cache it.
  Map<dynamic, dynamic> _cachedDeviceInfo;

  /// Information derived from `android.os.Build`.
  ///
  /// See: https://developer.android.com/reference/android/os/Build.html
  Future<Map<dynamic, dynamic>> get headerInfo async =>
      _cachedDeviceInfo ?? await _channel.invokeMethod('getHeaderInfo');

  ///Android获取SharedPreferences存储的值
  Future<String> getCacheInfo(String spName, String spKey) async {
    final Map<String, String> params = <String, String>{
      'spName': '$spName',
      'spKey': '$spKey'
    };
    return await _channel.invokeMethod('getCacheInfo', params);
  }

  ///Android向SharedPreferences存储值
  Future<bool> putCacheInfo(String spName, String spKey, String spValue) async {
    final Map<String, String> params = <String, String>{
      'spName': '$spName',
      'spKey': '$spKey',
      'spValue': '$spValue'
    };
    return await _channel.invokeMethod('putCacheInfo', params);
  }

  Future<bool> refreshAlbum(String imageAbsolutePath,
      {bool isInsertAlbum = false,
      bool isReplaceOld = true,
      bool isNotifyAlbum = false}) async {
    final Map<String, Object> params = <String, Object>{
      'imageAbsolutePath': '$imageAbsolutePath',
      'isInsertAlbum': isInsertAlbum,
      'isReplaceOld': isReplaceOld,
      'isNotifyAlbum': isNotifyAlbum
    };
    return await _channel.invokeMethod('refreshAlbum', params);
  }

  /// This information does not change from call to call. Cache it.
//  IosDeviceInfo _cachedIosDeviceInfo;

  /// Information derived from `UIDevice`.
  ///
  /// See: https://developer.apple.com/documentation/uikit/uidevice
//  Future<IosDeviceInfo> get iosInfo async => _cachedIosDeviceInfo ??=
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
//  IosDeviceInfo._fromMap(await channel.invokeMethod('getIosDeviceInfo'));
}
